/*
 * Copyright:  2018 smarabbit studio.
 *
 *  Licensed under the Confluent Community License; you may not use this file
 *  except in compliance with the License.  You may obtain a copy of the License at
 *
 *  http://www.confluent.io/confluent-community-license
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 *  WARRANTIES OF ANY KIND, either express or implied.  See the License for the
 *  specific language governing permissions and limitations under the License.
 *
 *  @作   者： 黄开晖 (117227773@qq.com)
 *  @日   期:  2021年9月19日
 */
package com.massyframework.beanskin.license.signature.wizard;

import java.util.List;

import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.TextArea;

/**
 * 签发控制器
 * @author huangkh
 *
 */
public class SignatureController extends Controller {

	@FXML
	private Button btnPrevious;
	@FXML
	private Button btnNext;
	@FXML
	private TextArea txtModules;
		
	/**
	 * 
	 */
	public SignatureController() {
	}

	@Override
	protected void init() {
	}

	@Override
	public void destroy() {
	}
	
	@Override
	public void beforeShow() {
		this.txtModules.clear();
		final List<Module> signaModules = 
				this.getWizard().getSignatureData().getSignaModules();
		signaModules.clear();
		
		CertificateEntry entry = this.getWizard().getSignatureData().getCertificateEntry();
		String alias = entry.getAlias();
		
		ObservableList<Module>  modules = this.getWizard().getSignatureData().getModules();
		for (Module module: modules) {
			if (alias.equals(module.getCertAlias())) {
				StringBuilder builder= new StringBuilder();
				builder.append(module.getName())
				    .append("  ")
					.append("[")
						.append(module.getCoordinate())
						.append("]");
				this.txtModules.appendText(builder.toString());
				signaModules.add(module);
			}
		}
		
		this.btnNext.setDefaultButton(signaModules.isEmpty());
	}

	@FXML
	protected void onPreviousClick(){
		this.getWizard().doPrevious();
	}
	
	@FXML
	protected void onNextClick() {
		this.getWizard().doNext();
	}
}
